package graph;
//https://leetcode.cn/problems/find-the-town-judge/description/
public class _0997找到小镇的法官 {
    class Solution {
        public int findJudge(int n, int[][] trust) {
            int[] in = new int[n+1];
            int[] out = new int[n+1];
            for(int[] tmp : trust){
                int x = tmp[0], y = tmp[1];
                in[y]++;
                out[x]++;
            }
            for(int i=1; i<=n; i++){
                if(in[i]==n-1 && out[i] == 0)
                    return i;
            }
            return -1;
        }
    }
}
